package com.ruiysoft.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruiysoft.crm.entity.FsDirectory;
import com.ruiysoft.crm.entity.FsGateway;
import com.ruiysoft.crm.model.entity.SysUser;
import com.ruiysoft.crm.service.IFsGatewayService;
import com.ruiysoft.crm.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * freeswitch pstn 网关 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-03-04
 */
@RestController
@RequestMapping("/fsGateway")
public class FsGatewayController {
    @Autowired
    IFsGatewayService gatewayService;

    @Autowired
    SysUserService sysUserService;

    @GetMapping("/list")
    public Object list(@RequestHeader String userId) {
        Map<String, Object> map = new HashMap<>();

        SysUser sysUser = sysUserService.getById(userId);
        if(sysUser != null) {
            map.put("rows", gatewayService.list(new QueryWrapper<FsGateway>().eq("enterpriseCode", sysUser.getEnterpriseId())));
            map.put("totalCount", gatewayService.count(new QueryWrapper<FsGateway>().eq("enterpriseCode", sysUser.getEnterpriseId())));
        }

        return map;
    }
}
